package com.example.douyin.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.douyin.R;
import com.example.lib_base_mvvm.entity.VideoEntity;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.List;

public class VideoAdapter extends BaseMultiItemQuickAdapter<VideoEntity.DataBean,BaseViewHolder> {
    public VideoAdapter(@Nullable List<VideoEntity.DataBean> data) {
        super(data);
        addItemType(0,R.layout.item_video_normal);//普通
        addItemType(1,R.layout.item_video_zhibo);//直播
        addItemType(2,R.layout.item_video_full);//全屏
        addItemType(5,R.layout.item_video_normal);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, VideoEntity.DataBean bean) {
        switch (bean.getItemType()){
            case 0:
            case 2:
            case 5:
            {
                //获取视频播放器
                StandardGSYVideoPlayer player = holder.findView(R.id.gsy);
                player.setUp(bean.getVideopath(),true,"");
                player.startPlayLogic();
                player.getBackButton().setVisibility(View.GONE);//返回图标消失
                //可进行全屏观看
                player.setShowFullAnimation(true);
                player.setLockLand(true);
                player.setAutoFullWithSize(false);

                //设置文字变化
                holder.setText(R.id.tv_dianzan,bean.getLike_count()+"");
                holder.setText(R.id.tv_username,bean.getAuthname()+"");
                holder.setText(R.id.tv_caption,bean.getCaption()+"");
                holder.setText(R.id.tv_pao,bean.getAuthname()+"创作的原声音乐");

                ImageView ivHead = holder.findView(R.id.iv_head);
                ImageView ivZhuan = holder.findView(R.id.iv_zhuan);
                ImageView ivDianzan = holder.findView(R.id.iv_dianzan);
                ImageView ivAdd = holder.findView(R.id.iv_add);

                Glide.with(getContext()).load(bean.getHeadpath()).circleCrop().into(ivHead);
                Glide.with(getContext()).load(bean.getHeadpath()).circleCrop().into(ivZhuan);

                if(bean.getDianzan()==1){//点赞了
                    ivDianzan.setImageResource(R.drawable.ic_xihuanred);
                }else{
                    ivDianzan.setImageResource(R.drawable.ic_xihuan);
                }
                if(bean.getGuanzhu()==1){//关注了
                    ivAdd.setVisibility(View.GONE);
                }else{
                    ivAdd.setVisibility(View.VISIBLE);
                }

                //跑马灯效果
                TextView tvPao = holder.findView(R.id.tv_pao);
                tvPao.requestFocus();
            }
            break;
            case 1:
            {
                //获取视频播放器
                StandardGSYVideoPlayer player = holder.findView(R.id.gsy);
                player.setUp(bean.getVideopath(),true,"");
                player.startPlayLogic();

                holder.setText(R.id.tv_username,bean.getAuthname()+"");
                holder.setText(R.id.tv_caption,bean.getCaption()+"");
                holder.setText(R.id.tv_pao,bean.getAuthname()+"创作的原声音乐");
                //跑马灯效果
                TextView tvPao = holder.findView(R.id.tv_pao);
                tvPao.requestFocus();
            }
                break;
        }
    }
}
